from Tkinter import *
from PIL import Image, ImageTk
import random

cards = [i%8 for i in range(16)]#arreglo de 16, numeros del 0-7
random.shuffle(cards)

class Application(Frame):
    def say_hi(self):
        print "hi there, everyone!"
        
    def button0_clicked(self):
        self.buttons[0][0]["image"] = self.heroPhoto[cards[0]]
        #button["state"] = DISABLED        
    def button1_clicked(self):
        self.buttons[0][1]["image"] = self.heroPhoto[cards[1]]
        #button["state"] = DISABLED
    def button2_clicked(self):
        self.buttons[0][2]["image"] = self.heroPhoto[cards[2]]
        #button["state"] = DISABLED
    def button3_clicked(self):
        self.buttons[0][3]["image"] = self.heroPhoto[cards[3]]
        #button["state"] = DISABLED
    def button4_clicked(self):
        self.buttons[1][0]["image"] = self.heroPhoto[cards[4]]
        #button["state"] = DISABLED
    def button5_clicked(self):
        self.buttons[1][1]["image"] = self.heroPhoto[cards[5]]
        #button["state"] = DISABLED
    def button6_clicked(self):
        self.buttons[1][2]["image"] = self.heroPhoto[cards[6]]
        #button["state"] = DISABLED
    def button7_clicked(self):
        self.buttons[1][3]["image"] = self.heroPhoto[cards[7]]
        #button["state"] = DISABLED
    def button8_clicked(self):
        self.buttons[2][0]["image"] = self.heroPhoto[cards[8]]
        #button["state"] = DISABLED
    def button9_clicked(self):
        self.buttons[2][1]["image"] = self.heroPhoto[cards[9]]
        #button["state"] = DISABLED
    def button10_clicked(self):
        self.buttons[2][2]["image"] = self.heroPhoto[cards[10]]
        #button["state"] = DISABLED
    def button11_clicked(self):
        self.buttons[2][3]["image"] = self.heroPhoto[cards[11]]
        #button["state"] = DISABLED
    def button12_clicked(self):
        self.buttons[3][0]["image"] = self.heroPhoto[cards[12]]
        #button["state"] = DISABLED
    def button13_clicked(self):
        self.buttons[3][1]["image"] = self.heroPhoto[cards[13]]
        #button["state"] = DISABLED
    def button14_clicked(self):
        self.buttons[3][2]["image"] = self.heroPhoto[cards[14]]
        #button["state"] = DISABLED
    def button15_clicked(self):
        self.buttons[3][3]["image"] = self.heroPhoto[cards[15]]
        #button["state"] = DISABLED

        #else:
         #   button.set_label("?")

    def createWidgets(self):
        size = 4
        #cards=get_cards()
        #random.shuffle(cards)
        IconImages = [Image.open("/home/cy/sphinx/python/images/dota.jpg"),
                      Image.open("/home/cy/sphinx/python/images/aegis.jpg")]
        HeroImages = [Image.open("/home/cy/sphinx/python/images/"+str(i)+".jpg") for i in range(8)]
        self.photo = [ImageTk.PhotoImage(IconImages[0]),ImageTk.PhotoImage(IconImages[1])]
        self.heroPhoto = [ImageTk.PhotoImage(HeroImages[i]) for i in range(8)]
        #photo =[PhotoImage(file="/home/cy/sphinx/python/images/"+str(1)+".png") for i in range(size*size)]
        
        
        self.buttons = [[Button(self) for i in range(size)]for j in range(size)]
        for i in range(size):
            for j in range(size):
                self.buttons[i][j].grid(row=i, column=j)
                #self.buttons[i][j]["text"] = i+j+(size-1)*i
                self.buttons[i][j]["image"] = self.photo[0]
                self.buttons[i][j]["command"] = eval("self.button"+str(i+j+(size-1)*i)+"_clicked")#(self.buttons[i][j],cards[i+j+(size-1)*i])
                
        
        
        self.QUIT = Button(self)
        self.QUIT["text"] = "QUIT"
        self.QUIT["fg"]   = "red"
        self.QUIT["command"] =  self.quit

        self.QUIT.grid(row=7, column=1)

        self.hi_there = Button(self)
        self.hi_there["text"] = "Hello",
        self.hi_there["command"] = self.say_hi

        self.hi_there.grid(row=7, column=2)



    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

root = Tk()
app = Application(master=root)
app.mainloop
root.destroy()